import {Component, OnInit} from '@angular/core';
import {Observable} from 'rxjs';
import {Http} from '@angular/http';
import {Router, ActivatedRoute} from '@angular/router';

@Component({
  selector: 'app-user-edit',
  templateUrl: './user-edit.component.html',
  styleUrls: ['./user-edit.component.css']
})
export class UserEditComponent implements OnInit {
  public user: any = {};

  private id: any;
  private dataSource: Observable<any>;
  responseErr: string;

  getDetail() {
    this.dataSource = this.http.post(`user/detail?id=${this.id}`, null).map(res => res.json())
    this.dataSource.subscribe(data => {
      if (data.code === 0) {
        this.user = data.data;
      } else {
        alert(data.msg)
      }
    });
  }

  constructor(private http: Http, private router: Router, private route: ActivatedRoute) {
  }

  ngOnInit() {
    this.id = this.route.snapshot.paramMap.get('id');
    this.id !== 'add' && this.getDetail()
  }

}
